package collections.list;

import java.util.*;

public class SortDemo {

  public static void main(String[] args) {

    List<Index> list = new ArrayList() {
      {

        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.1f));
        add(new Index("a酒店", "hotel", 2.4f));


        add(new Index("1餐厅", "food", 2.5f));
        add(new Index("2餐厅", "food", 2.1f));
        add(new Index("3餐厅", "food", 2.1f));
        add(new Index("4餐厅", "food", 2.4f));
        add(new Index("5餐厅", "food", 2.1f));
        add(new Index("6餐厅", "food", 2.1f));
        add(new Index("7餐厅", "food", 2.1f));
        add(new Index("8餐厅", "food", 2.1f));

        add(new Index("1景点", "sight", 2.1f));
        add(new Index("2景点", "sight", 2.1f));
        add(new Index("3景点", "sight", 2.1f));
        add(new Index("4景点", "sight", 2.1f));
        add(new Index("5景点", "sight", 2.1f));
        add(new Index("6景点", "sight", 2.1f));
        add(new Index("7景点", "sight", 2.1f));
        add(new Index("8景点", "sight", 2.1f));


        add(new Index("1一日游", "huodong", 2.1f));
        add(new Index("2一日游", "huodong", 2.1f));
        add(new Index("3一日游", "huodong", 2.1f));
        add(new Index("4一日游", "huodong", 2.1f));
        add(new Index("5一日游", "huodong", 2.1f));
        add(new Index("6一日游", "huodong", 2.1f));
        add(new Index("7一日游", "huodong", 2.1f));
        add(new Index("8一日游", "huodong", 2.1f));
      }
    };

    Collections.sort(list, new Comparator<Index>() {
      @Override
      public int compare(Index o1, Index o2) {
        if (o1.type.equals(o2.type)) {
          return 0;
        }
        return Float.compare( o2.score,o1.score);
      }
    });

    for (Index index : list) {
      System.out.println(index);
    }
  }

  private static class Index {

    String name;

    String type;

    float score;

    public Index(String name, String type, float score) {
      this.name = name;
      this.type = type;
      this.score = score;
    }

    @Override
    public String toString() {
      return "Index{" +
              "name='" + name + '\'' +
              ", type='" + type + '\'' +
              ", score=" + score +
              '}';
    }
  }

}

